package ve.usb.ddp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import ve.usb.cohesion.runtime.CohesionAction;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import ve.usb.cohesion.runtime.HibernateUtil;
import ve.usb.ddp.hibernate.*;


/**
 * Manejo de elementos de la entidad PaiPermisoNoRemunerado.<br>
 */
public class AccionesPaiPermisoNoRemunerado extends CohesionAction {
    
/**
     * Called by Struts for the execution of action APreBuscar_paiPermisoNoRemunerado.
     * Prepara la vista de selección de criterios de búsqueda para una entidad.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APreBuscar_paiPermisoNoRemunerado(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"VBuscar_paiPermisoNoRemunerado", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiPermisoNoRemuneradoBuscar.clear(mapping, request);

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action APreCrear_paiPermisoNoRemunerado.
     * Prepara la vista de captura de datos de una entidad para realizar una inserción.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APreCrear_paiPermisoNoRemunerado(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"VCrear_paiPermisoNoRemunerado", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiPermisoNoRemunerado fFPaiPermisoNoRemunerado = FPaiPermisoNoRemunerado.clear(mapping, request);

             //Feed for combo listPaiEstudio.
             {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(pais, idEstudio) " + 
                "from PaiEstudio").list();
              list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
              fFPaiPermisoNoRemunerado.setListPaiEstudio(list);
             }


            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action ABuscar_paiPermisoNoRemunerado.
     * Captura los criterios de búsqueda y los fija en la sesión.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward ABuscar_paiPermisoNoRemunerado(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"APreListar_paiPermisoNoRemunerado", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiPermisoNoRemuneradoBuscar fFPaiPermisoNoRemuneradoBuscar = (FPaiPermisoNoRemuneradoBuscar)form;
            request.getSession().setAttribute("ABuscar_paiPermisoNoRemunerado_campo", "informe_entregado");
            request.getSession().setAttribute("ABuscar_paiPermisoNoRemunerado_valor", "%" + fFPaiPermisoNoRemuneradoBuscar.getInforme_entregado() + "%");

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action APreListar_paiPermisoNoRemunerado.
     * Selecciona las entidades a ser listadas de acuerdo a los parámetros recibidos.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APreListar_paiPermisoNoRemunerado(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"VListar_paiPermisoNoRemunerado", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            String crit = (String)request.getSession().getAttribute("ABuscar_paiPermisoNoRemunerado_campo");
            java.util.List<PaiPermisoNoRemunerado> list;
            if (crit==null) {
                list = (java.util.List<PaiPermisoNoRemunerado>)s.createQuery("from PaiPermisoNoRemunerado").list();
            } else {
                String valor = (String)request.getSession().getAttribute("ABuscar_paiPermisoNoRemunerado_valor");
                list = (java.util.List<PaiPermisoNoRemunerado>)
                   s.createQuery("from PaiPermisoNoRemunerado where "+crit+" like :valor")
                    .setString("valor", valor).list();
                request.getSession().removeAttribute("ABuscar_paiPermisoNoRemunerado_campo");
                request.getSession().removeAttribute("ABuscar_paiPermisoNoRemunerado_valor");
            }
            request.setAttribute("L_PaiPermisoNoRemunerado", list);
            for (PaiPermisoNoRemunerado paiPermisoNoRemunerado:list) {
                if (paiPermisoNoRemunerado.getResolucion()!=null) paiPermisoNoRemunerado.getResolucion().getPais();
            }


            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action APre_paiPermisoNoRemunerado.
     * Prepara la vista de actualización de una entidad.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APre_paiPermisoNoRemunerado(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"V_paiPermisoNoRemunerado", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            Long idPermiso_no_Remunerado = lookup_Long(request, "idPermiso_no_Remunerado");
            
            FPaiPermisoNoRemunerado fFPaiPermisoNoRemunerado = FPaiPermisoNoRemunerado.clear(mapping, request);
            PaiPermisoNoRemunerado paiPermisoNoRemunerado = (PaiPermisoNoRemunerado)s.load(PaiPermisoNoRemunerado.class, idPermiso_no_Remunerado);
            fFPaiPermisoNoRemunerado.setIdPermiso_no_Remunerado(paiPermisoNoRemunerado.getIdPermiso_no_Remunerado());
            if (paiPermisoNoRemunerado.getResolucion()!=null) {
                fFPaiPermisoNoRemunerado.setResolucion(paiPermisoNoRemunerado.getResolucion().getIdEstudio());
            } else {
                fFPaiPermisoNoRemunerado.setResolucion(0L);
            }
            fFPaiPermisoNoRemunerado.setInforme_entregado(paiPermisoNoRemunerado.getInforme_entregado());
            fFPaiPermisoNoRemunerado.setOtorgado(paiPermisoNoRemunerado.getOtorgado());
            fFPaiPermisoNoRemunerado.setFec_Vencimiento(paiPermisoNoRemunerado.getFec_Vencimiento().toString());

            //Feed for combo listPaiEstudio.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(pais, idEstudio) " + 
               "from PaiEstudio").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFPaiPermisoNoRemunerado.setListPaiEstudio(list);
            }

            request.getSession().setAttribute("idPermiso_no_Remunerado", idPermiso_no_Remunerado);
            request.getSession().setAttribute("idPermiso_no_Remunerado_super", idPermiso_no_Remunerado);

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action AAct_paiPermisoNoRemunerado.
     * Registro de actualizaciones de una entidad.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward AAct_paiPermisoNoRemunerado(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"V_paiPermisoNoRemunerado", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiPermisoNoRemunerado fFPaiPermisoNoRemunerado = (FPaiPermisoNoRemunerado)form;
            PaiPermisoNoRemunerado paiPermisoNoRemunerado = (PaiPermisoNoRemunerado)s.load(PaiPermisoNoRemunerado.class, fFPaiPermisoNoRemunerado.getIdPermiso_no_Remunerado());
            if (fFPaiPermisoNoRemunerado.getResolucion()==0) paiPermisoNoRemunerado.setResolucion(null);
            else if ((paiPermisoNoRemunerado.getResolucion()==null) ||
                    (paiPermisoNoRemunerado.getResolucion().getIdEstudio()!=fFPaiPermisoNoRemunerado.getResolucion())) {
                PaiEstudio __obj = (PaiEstudio)s.load(PaiEstudio.class, fFPaiPermisoNoRemunerado.getResolucion());
                paiPermisoNoRemunerado.setResolucion(__obj);
            }
            paiPermisoNoRemunerado.setInforme_entregado(fFPaiPermisoNoRemunerado.getInforme_entregado());
            paiPermisoNoRemunerado.setOtorgado(fFPaiPermisoNoRemunerado.getOtorgado());
            paiPermisoNoRemunerado.setFec_Vencimiento(new ve.usb.cohesion.runtime.LocalDate(fFPaiPermisoNoRemunerado.getFec_Vencimiento()));


            //Feed for combo listPaiEstudio.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(pais, idEstudio) " + 
               "from PaiEstudio").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFPaiPermisoNoRemunerado.setListPaiEstudio(list);
            }

            request.getSession().setAttribute("idPermiso_no_Remunerado", paiPermisoNoRemunerado.getIdPermiso_no_Remunerado());
            request.getSession().setAttribute("idPermiso_no_Remunerado_super", paiPermisoNoRemunerado.getIdPermiso_no_Remunerado());

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        if (salida==0) {
          request.setAttribute("msg",
            getResources(request).getMessage("AAct_paiPermisoNoRemunerado.msg0"));
        }

        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action AElim_paiPermisoNoRemunerado.
     * Elimina la entidad seleccionada.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward AElim_paiPermisoNoRemunerado(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"APreListar_paiPermisoNoRemunerado", "V_paiPermisoNoRemunerado", };
        final int SALIDA_0 = 0;
        final int SALIDA_1 = 1;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            Long idPermiso_no_Remunerado = lookup_Long(request, "idPermiso_no_Remunerado");
            PaiPermisoNoRemunerado paiPermisoNoRemunerado = (PaiPermisoNoRemunerado)s.load(PaiPermisoNoRemunerado.class, idPermiso_no_Remunerado);
            s.delete(paiPermisoNoRemunerado);
            try {
                s.flush();
            } catch (Exception ex1) {
                ex1.printStackTrace();
                salida = SALIDA_1;
            }

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        if (salida==0) {
          request.setAttribute("msg",
            getResources(request).getMessage("AElim_paiPermisoNoRemunerado.msg0"));
        }
        if (salida==1) {
          request.setAttribute("msg",
            getResources(request).getMessage("AElim_paiPermisoNoRemunerado.msg1"));
        }

        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action ACrear_paiPermisoNoRemunerado.
     * Registro de la creación de una PaiPermisoNoRemunerado.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward ACrear_paiPermisoNoRemunerado(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"V_paiPermisoNoRemunerado", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiPermisoNoRemunerado fFPaiPermisoNoRemunerado = (FPaiPermisoNoRemunerado)form;
            PaiPermisoNoRemunerado paiPermisoNoRemunerado = new PaiPermisoNoRemunerado();
            if (fFPaiPermisoNoRemunerado.getResolucion()==0) paiPermisoNoRemunerado.setResolucion(null);
            else {
                PaiEstudio __obj = (PaiEstudio)s.load(PaiEstudio.class, fFPaiPermisoNoRemunerado.getResolucion());
                paiPermisoNoRemunerado.setResolucion(__obj);
            }
            paiPermisoNoRemunerado.setInforme_entregado(fFPaiPermisoNoRemunerado.getInforme_entregado());
            paiPermisoNoRemunerado.setOtorgado(fFPaiPermisoNoRemunerado.getOtorgado());
            paiPermisoNoRemunerado.setFec_Vencimiento(new ve.usb.cohesion.runtime.LocalDate(fFPaiPermisoNoRemunerado.getFec_Vencimiento()));

            s.save(paiPermisoNoRemunerado);
            s.flush();
            fFPaiPermisoNoRemunerado.setIdPermiso_no_Remunerado(paiPermisoNoRemunerado.getIdPermiso_no_Remunerado());

            //Feed for combo listPaiEstudio.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(pais, idEstudio) " + 
               "from PaiEstudio").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFPaiPermisoNoRemunerado.setListPaiEstudio(list);
            }

            request.getSession().setAttribute("idPermiso_no_Remunerado", paiPermisoNoRemunerado.getIdPermiso_no_Remunerado());
            request.getSession().setAttribute("idPermiso_no_Remunerado_super", paiPermisoNoRemunerado.getIdPermiso_no_Remunerado());

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        if (salida==0) {
          request.setAttribute("msg",
            getResources(request).getMessage("ACrear_paiPermisoNoRemunerado.msg0"));
        }

        return mapping.findForward(SALIDAS[salida]);
    }



}